package com.chainyoung.component_tmperson.ui.view;

import android.content.Context;
import android.graphics.Color;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutCompat;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chainyoung.common.utils.ConvertUtils;
import com.chainyoung.component_tmperson.entity.WalletPercent;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;

public class WalletPercentDetailView extends LinearLayout {


    public WalletPercentDetailView(Context context) {
        super(context);
    }

    public WalletPercentDetailView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    public WalletPercentDetailView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    public void setViews(List<WalletPercent> data) {
        this.setOrientation(HORIZONTAL);
        int totalWidth = this.getWidth();
        this.removeAllViews();
        if (data.isEmpty()) {
            TextView textView = new TextView(getContext());
            textView.setLayoutParams(new LinearLayoutCompat.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
            textView.setTextColor(Color.parseColor("#ffffff"));
            textView.setTextSize(11);
            textView.setText("转入资产后可以在此处查看资产配置比");
            this.addView(textView);
            return;
        }
        for (WalletPercent item : data) {
            TextView textView = new TextView(getContext());
            textView.setLayoutParams(new LinearLayoutCompat.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
            textView.setTextColor(Color.parseColor(item.getColor()));
            textView.setTextSize(11);
            textView.setText(String.format("%s %s%% ", item.getCoinName(), new BigDecimal(item.getPercent() * 100).setScale(2, RoundingMode.DOWN).toPlainString()));
            this.addView(textView);
        }
    }


}

